<%@ page contentType="application/xhtml+xml;charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld"%>

<jsp:useBean id="data" scope="page"
             class="cz.muni.fi.xvano1.trinity.supplementary.DataSupplier"/>
<c:if test="${applicationScope.yearList eq null}">
    <c:set var="years" value="${data.years}"/>
</c:if>
<c:if test="${applicationScope.yearList ne null}">
    <c:set var="years" value="${applicationScope.yearList}"/>
</c:if>

<c:if test="${action=='calendarOptions'}">
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select type of view."/><br/><br/>
        <c:out value="Type: "/>
        <stripes:select name="viewType">
            <stripes:options-collection collection="${data.views}"/>
        </stripes:select>
        <stripes:submit name ="selectViewType" value="Submit"/>
    </stripes:form> 
</c:if>
<c:if test="${action=='yearlyView' && empty year}">
    <c:out value="Yearly view for ?"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select year."/><br/><br/>
        <c:out value="Year: "/>
        <stripes:select name="year">
            <stripes:options-collection collection="${years}"/>
        </stripes:select>
        <stripes:hidden name="viewType" value="yearlyView"/>
        <stripes:submit name ="selectYearOfYearly" value="Submit"/>
    </stripes:form>
</c:if>
<c:if test="${action=='yearlyView' && not empty year}">
    <c:out value="Yearly view for ${year}"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select components."/><br/><br/>
        <c:set var="i" value="1"/>
        <table>
            <tbody>
                <c:forEach var="key" items="${allowedKeys}">
                    <c:if test="${i mod 4 == 1}">
                        <tr>
                        </c:if>
                        <td>
                            <stripes:checkbox name="${key}"/>
                            <c:out value=" ${key} "/>
                        </td>
                        <c:if test="${i mod 4 == 0}">
                        </tr>
                    </c:if>
                    <c:set var="i" value="${i+1}"/>
                </c:forEach>
            </tbody>
        </table>
        <stripes:hidden name="viewType" value="yearlyView"/>
        <stripes:hidden name="year" value="${year}"/>
        <stripes:submit name ="viewYearlyCalendar" value="Submit"/>
    </stripes:form>
</c:if>



<c:if test="${action=='monthlyView'&& empty year && empty month}">
    <c:out value="Monthly view for ?/?"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select year."/><br/><br/>
        <c:out value="Year: "/>
        <stripes:select name="year">
            <stripes:options-collection collection="${years}"/>
        </stripes:select>
        <stripes:hidden name="viewType" value="monthlyView"/>
        <stripes:submit name ="selectYearOfMonthly" value="Submit"/>
    </stripes:form>
</c:if>
<c:if test="${action=='monthlyView'&& not empty year && empty month}">
    <c:out value="Monthly view for ${year}/?"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select month."/><br/><br/>
        <c:out value="Month: "/>
        <stripes:select name="month">
            <stripes:options-collection collection="${data.months}"/>
        </stripes:select>
        <stripes:hidden name="year" value="${year}"/>
        <stripes:hidden name="viewType" value="monthlyView"/>
        <stripes:submit name ="selectMonthOfMonthly" value="Submit"/>
    </stripes:form>
</c:if>
<c:if test="${action=='monthlyView'&& not empty year && not empty month}">
    <c:out value="Monthly view for ${year}/${month}"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select components."/><br/><br/>
        <c:set var="i" value="1"/>
        <table>
            <tbody>
                <c:forEach var="key" items="${allowedKeys}">
                    <c:if test="${i mod 4 == 1}">
                        <tr>
                        </c:if>
                        <td>
                            <stripes:checkbox name="${key}"/>
                            <c:out value=" ${key} "/>
                        </td>
                        <c:if test="${i mod 4 == 0}">
                        </tr>
                    </c:if>
                    <c:set var="i" value="${i+1}"/>
                </c:forEach>
            </tbody>
        </table>
        <stripes:hidden name="year" value="${year}"/>
        <stripes:hidden name="month" value="${month}"/>
        <stripes:hidden name="viewType" value="monthlyView"/>
        <stripes:submit name ="viewMonthlyCalendar" value="Submit"/>
    </stripes:form>
</c:if>



<c:if test="${action=='weeklyView'&& empty year && empty week}">
    <c:out value="Weekly view for ?/?"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select year."/><br/><br/>
        <c:out value="Year: "/>
        <stripes:select name="year">
            <stripes:options-collection collection="${years}"/>
        </stripes:select>
        <stripes:hidden name="viewType" value="weeklyView"/>
        <stripes:submit name ="selectYearOfWeekly" value="Submit"/>
    </stripes:form>
</c:if>
<c:if test="${action=='weeklyView'&& not empty year && empty week}">
    <c:out value="Weekly view for ${year}/?"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select week."/><br/><br/>
        <c:out value="Week: "/>
        <stripes:select name="week">
            <stripes:options-collection collection="${weeks}"/>
        </stripes:select>
        <stripes:hidden name="year" value="${year}"/>
        <stripes:hidden name="viewType" value="weeklyView"/>
        <stripes:submit name ="selectWeekOfWeekly" value="Submit"/>
    </stripes:form>
</c:if>
<c:if test="${action=='weeklyView'&& not empty year && not empty week}">
    <c:out value="Weekly view for ${year}/${week}"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select components."/><br/><br/>
        <c:set var="i" value="1"/>
        <table>
            <tbody>
                <c:forEach var="key" items="${allowedKeys}">
                    <c:if test="${i mod 4 == 1}">
                        <tr>
                        </c:if>
                        <td>
                            <stripes:checkbox name="${key}"/>
                            <c:out value=" ${key} "/>
                        </td>
                        <c:if test="${i mod 4 == 0}">
                        </tr>
                    </c:if>
                    <c:set var="i" value="${i+1}"/>
                </c:forEach>
            </tbody>
        </table>
        <stripes:hidden name="year" value="${year}"/>
        <stripes:hidden name="week" value="${week}"/>
        <stripes:hidden name="viewType" value="weeklyView"/>
        <stripes:submit name ="viewWeeklyCalendar" value="Submit"/>
    </stripes:form>
</c:if>



<c:if test="${action=='dailyView'&& empty year && empty month && empty day}">
    <c:out value="Daily view for ?/?/?"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select year."/><br/><br/>
        <c:out value="Year: "/>
        <stripes:select name="year">
            <stripes:options-collection collection="${years}"/>
        </stripes:select>
        <stripes:hidden name="viewType" value="dailyView"/>
        <stripes:submit name ="selectYearOfDaily" value="Submit"/>
    </stripes:form>
</c:if>
<c:if test="${action=='dailyView'&& not empty year && empty month && empty day}">
    <c:out value="Daily view for ${year}/?/?"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select month."/><br/><br/>
        <c:out value="Month: "/>
        <stripes:select name="month">
            <stripes:options-collection collection="${data.months}"/>
        </stripes:select>
        <stripes:hidden name="year" value="${year}"/>
        <stripes:hidden name="viewType" value="dailyView"/>
        <stripes:submit name ="selectMonthOfDaily" value="Submit"/>
    </stripes:form>
</c:if>
<c:if test="${action=='dailyView'&& not empty year && not empty month && empty day}">
    <c:out value="Daily view for ${year}/${month}/?"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select day."/><br/><br/>
        <c:out value="Day: "/>
        <stripes:select name="day">
            <stripes:options-collection collection="${days}"/>
        </stripes:select>
        <stripes:hidden name="year" value="${year}"/>
        <stripes:hidden name="month" value="${month}"/>
        <stripes:hidden name="viewType" value="dailyView"/>
        <stripes:submit name ="selectDayOfDaily" value="Submit"/>
    </stripes:form>
</c:if>
<c:if test="${action=='dailyView'&& not empty year && not empty month && not empty day}">
    <c:out value="Daily view for ${year}/${month}/${day}"/><br/><br/>
    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean">
        <c:out value="Please select components."/><br/><br/>
        <c:set var="i" value="1"/>
        <table>
            <tbody>
                <c:forEach var="key" items="${allowedKeys}">
                    <c:if test="${i mod 4 == 1}">
                        <tr>
                        </c:if>
                        <td>
                            <stripes:checkbox name="${key}"/>
                            <c:out value=" ${key} "/>
                        </td>
                        <c:if test="${i mod 4 == 0}">
                        </tr>
                    </c:if>
                    <c:set var="i" value="${i+1}"/>
                </c:forEach>
            </tbody>
        </table>
        <stripes:hidden name="year" value="${year}"/>
        <stripes:hidden name="month" value="${month}"/>
        <stripes:hidden name="day" value="${day}"/>
        <stripes:hidden name="viewType" value="dailyView"/>
        <stripes:submit name ="viewDailyCalendar" value="Submit"/>
    </stripes:form>
</c:if>
